﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoodTrader.GTDownload
{
    public class CpOptionATM
    {
        private string[] mATMArray = null;
        public string[] ATMArray
        {
            get { return mATMArray; }
            set { mATMArray = value; }
        }
        private DSCBO1Lib.OptionAtm m_OptionAtmFetcher = new DSCBO1Lib.OptionAtm();

        public CpOptionATM()
        {
            m_OptionAtmFetcher.Received += new DSCBO1Lib._IDibEvents_ReceivedEventHandler(OnReceived);
        }

        public void Download()
        {
            try
            {
                // 데이터 수신 요청을 한다.
                m_OptionAtmFetcher.BlockRequest();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

        public void OnReceived()
        {
            object count = m_OptionAtmFetcher.GetHeaderValue(0);
            if (Convert.ToInt32(count) > 0)
            {
                mATMArray = new string[Convert.ToInt32(count)];
                for (int i = 0; i < Convert.ToInt32(count); i++)
                {
                    mATMArray[i] = m_OptionAtmFetcher.GetDataValue(0, i).ToString();
                }
            }
        }
    }
}
